#!c:/perl/bin/perl.exe

use WWCOM;
use CGI;
use strict;
	
my $DEBUG= 0;
$DIVA_DB::DEBUG= $DEBUG;

my $cgi= new CGI;
my %outvars;

my @names= <$WWCOM::VIEWSDIR/*.views>;
@names= sort {
	$a=~ /.*\/[0-9]+\.[0-9]+\.([0-9]{2})\-([0-9]{2})\-([0-9]{4})\.([0-9]{2})\-([0-9]{2})\-([0-9]{4})\.*/;
	my $newesta= $6.$5.$4;
	$b=~ /.*\/[0-9]+\.[0-9]+\.([0-9]{2})\-([0-9]{2})\-([0-9]{4})\.([0-9]{2})\-([0-9]{2})\-([0-9]{4})\.*/;
	my $newestb= $6.$5.$4;
	$newesta <=> $newestb;} @names; #sort files by content date

my (%emails);

for(my $i= 0; $i<=$#names; $i++) {
	print "File: $names[$i]\n";
	my %storyhash= &WWCOM::READFILE($names[$i]);
	
	foreach my $key (keys %storyhash) {
		#print "\tView: $key - $storyhash{$key}{'subject'}\n";
		if ($storyhash{$key}{'email'}=~ /.+\@.+\..+$/) {
			$emails{$storyhash{$key}{'email'}}= $storyhash{$key}{'author'};        
		}
	}
	
}


open FH,">emails.txt";
my @keys= sort {$emails{$a} cmp $emails{$b}} keys %emails;
for (@keys) {
	print FH qq~"$emails{$_}" <$_>,\n~;
}
close FH;
   
